package com.chris.homecare.screens
{
	import com.chris.homecare.TextureAtlasManager;
	
	import feathers.controls.Button;
	import feathers.controls.Header;
	import feathers.controls.Screen;
	
	import starling.display.DisplayObject;
	import starling.display.Image;
	import starling.display.Quad;
	import starling.events.Event;
	import starling.textures.Texture;
	
	[Event(name="complete",type="starling.events.Event")]
	public class IntroScreen extends Screen
	{
		private var header:Header;
		private var footer:Header;
		
		[Embed(source="/assets/images/homecare/banner-img.png")]
		private static const BANNER_IMG:Class;
		
		private var bannerImg:Image;
		private var footerLogoImg:Image;
		private var logoImg:Image;
		
		public function IntroScreen()
		{
			
		}
		
		override protected function initialize():void
		{
			super.initialize();

			bannerImg = new Image(Texture.fromBitmap(new BANNER_IMG()));
			addChild(bannerImg);
			
			header = new Header();
			logoImg = new Image(TextureAtlasManager.getAtlas().getTexture("speiuss"));
			addChild(header);
			
			footer = new Header();
			footerLogoImg = new Image(TextureAtlasManager.getAtlas().getTexture("speiusshealthcare"));
			addChild(footer);
			
			var menuBtn:Button = new Button();
			menuBtn.nameList.add("menu-btn");
			menuBtn.addEventListener(Event.TRIGGERED, menuBtnHandler);
			
			header.backgroundSkin = new Quad( 10, 10, 0x353535);
			footer.backgroundSkin = new Quad( 10, 10, 0x353535);
			footer.centerItems = new <DisplayObject> [footerLogoImg];
			header.rightItems = new <DisplayObject> [menuBtn];
			header.centerItems = new <DisplayObject> [logoImg];
		}
		
		override protected function draw():void
		{
			var stageWidth:int = stage.stageWidth;
			var stageHeight:int = stage.stageHeight;
			
			var bannerWidth:uint = 640;
			var bannerHeight:uint = 776;
			var ratio:Number;
			
			header.width = footer.width = stageWidth;
			
			var availHeight:uint = stageHeight + 5 - (header.height + footer.height);
			ratio = availHeight/bannerWidth;
			bannerImg.width = bannerWidth*ratio;
			bannerImg.height = bannerHeight*ratio;
			bannerImg.x = stageWidth - bannerImg.width;
			
			
			var scale:Number = (stageWidth - 30)/611;
			footerLogoImg.width = 611 * scale;
			footerLogoImg.height = 90 * scale;
			footerLogoImg.y = 10;
			footer.height = 40 + footerLogoImg.height;
			footer.y = stageHeight - footer.height;
			bannerImg.y = header.height-5;
			
			super.draw();
		}
		
		private function menuBtnHandler():void
		{
			this.dispatchEventWith(Event.COMPLETE);
		}
	}
}